package com.zmyuan.demo.netty.thrift.rpc;

import com.zmyuan.demo.netty.thrift.HelloWorldService;
import com.zmyuan.demo.netty.thrift.service.HelloWorldServiceImpl;
import org.apache.thrift.TProcessor;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.server.TServer;
import org.apache.thrift.server.TSimpleServer;
import org.apache.thrift.transport.TServerSocket;

/**
 * Created by zdb on 2017/2/17.
 */
public class ThriftRPCServer {

    public static void startRPCServer(int port) throws Exception {
        TProcessor processor = new HelloWorldService.Processor<HelloWorldService.Iface>(new HelloWorldServiceImpl());
        TServerSocket transport = new TServerSocket(port);
        TServer.Args args = new TServer.Args(transport);
        args.processor(processor);
        args.protocolFactory(new TBinaryProtocol.Factory());

        TServer server = new TSimpleServer(args);
        server.serve();
    }

    public static void main(String[] args) throws Exception {

        startRPCServer(8999);
    }
}
